<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <test></test>
        <demo></demo>
        <button @click="handleClick">发朋友圈</button>
    </div>
    <script src="./vue.js"></script>
    <script>
        // 方便实现总线模式的
        let bus = new Vue();
        Vue.component("test",{
            mounted() {
                bus.$on("test",function(msg){
                    console.log("朋友1收到消息了:",msg);
                })
                console.log(this.$root.num);
            },
            template:`
                <div><h1>Test 组件</h1></div>
            `
        })
        Vue.component("demo",{
            mounted(){
                bus.$on("test",function(msg){
                    console.log("朋友2收到消息了:",msg);
                })
            },
            template:`
                <div><h1>Demo组件</h1></div>
            `
        })
        let vm = new Vue({
            el:"#app",
            data:{
                num:100
            },
            methods: {
                handleClick:function(){
                    bus.$emit("test","今天天气真不错");
                }
            },
        })
    </script>
</body>
</html>